<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
  <meta charset="utf-8">
  <title>已办事宜</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/admin.css}" media="all">
  <link rel="stylesheet" th:href="@{/style/custom.css}" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto layui-form-pane" lay-filter="LAY-task-front-form">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">流程定义</label>
          <div class="layui-input-block">
            <select name="procDefKey" id="procDefKey" lay-search>
              <option value="">全部</option>
              <option th:each="map,idx:${procDefKeys}" th:value="${map.key}" th:text="${map.value}"></option>
            </select>
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">流程实例ID</label>
          <div class="layui-input-block">
            <input type="text" name="procInstId" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">业务流水号</label>
          <div class="layui-input-block">
            <input type="text" name="bizKey" placeholder="请输入" autocomplete="off" class="layui-input" lay-affix="clear">
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="LAY-task-front-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 搜索
          </button>
          <button class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="LAY-task-front-reset">
            <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i> 重置
          </button>
        </div>
      </div>
    </div>

    <div class="layui-card-body">
      <div class="layui-btn-group" style="padding-bottom: 10px;">
        <!--刷新table-->
        <button type="button" class="layui-btn layui-btn-normal btn-op-task layui-btn-sm" data-type="refresh">
          <i class="layui-icon">&#xe666;</i>刷新
        </button>
      </div>

      <!--table 定义-->
      <table id="LAY-task-table" lay-filter="LAY-task-table"></table>
    </div>
  </div>
</div>

<script th:src="@{/layui/layui.js}"></script>
<script>
  layui.config({
    base: '/'
  }).extend({
    flying: 'flying'
  }).use(['index', 'flying'], function(){
    const $ = layui.$
        ,admin = layui.admin
        ,form = layui.form
        ,table = layui.table
        ,layer = layui.layer
        ,dropdown = layui.dropdown
        ,flying = layui.flying;

    flying.table({
      elem: '#LAY-task-table',
      // url: '/flow/instance/task/completed/his', //数据接口
      url: '/flow/task/his/page', //数据接口
      cols: [
        {type: 'numbers', fixed: 'left', title: '序号'}
        , {field: 'bizKey', title: '业务流水号', width: 190}
        , {field: 'procInstName', title: '流程名称', minWidth: 150,}
        , {field: 'startUserId', title: '发起人', width: 145}
        , {field: 'taskName', title: '任务节点', minWidth: 120}
        , {field: 'userName', title: '任务处理人', width: 100}
        , {field: 'startTime', title: '开始时间', templet: '<div>{{ layui.util.toDateString(d.startTime, "yyyy-MM-dd HH:mm:ss") }}</div>',  minWidth: 170, sort: true}
        , {field: 'endTime', title: '结束时间', templet: '<div>{{ layui.util.toDateString(d.endTime, "yyyy-MM-dd HH:mm:ss") }}</div>',  minWidth: 170, sort: true}
        , {field: 'duration', title: '持续时间', templet: function (d) {
            return flying.formatDuration(d.duration);
          }, width: 180}
        , {field: 'result', title: '审批状态', templet: function (d) {
            if (d.result === 'A') {
              return '同意';
            } else if (d.result === 'R') {
              return '拒绝';
            } else if (d.result === 'D') {
              return '驳回';
            } else {
              return '未知';
            }
          }, width: 110}
        , {field: 'remark', title: '审批信息', width: 150}
        , {field: 'procInstId', title: '流程实例ID', minWidth: 120, hide: true}
      ]
    });

    //监听搜索
    form.on('submit(LAY-task-front-search)', function (data) {
      let field = data.field;
      //执行重载
      table.reload('LAY-task-table', {
        where: field
      });
    });
    // 监听重置
    form.on('submit(LAY-task-front-reset)', function (data) {
      let field = data.field;
      for (let key of Object.keys(field)) {
        field[key] = '';
      }
      form.val("LAY-task-front-form", field);
    });

    //事件
    let active = {
      refresh: function () {
        let data = form.val("LAY-task-front-form");
        //执行重载 数据刷新
        table.reload('LAY-task-table', {
          where: data
        });
      }
    };

    //执行事件操作
    layui.$('.layui-btn.btn-op-task').on('click', function () {
      let type = layui.$(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
</script>
</body>
</html>
